package com.qu.waibao.search;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qu.waibao.R;
import com.qu.waibao.base.BaseRecyclerAdapter;
import com.qu.waibao.bean.SearchHome;
import com.qu.waibao.home.adpater.PublishAdapter;
import com.qu.waibao.network.NetManager;
import com.qu.waibao.utils.ImageLoader;
import com.qu.waibao.widget.TweetPicturesLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * @描述 describe
 * @作者 Administrator
 * @创建时间 2018/7/25 16:16
 * @邮箱 1123599561@qq.com
 */
public class HomeSearchAdapter extends BaseRecyclerAdapter<SearchHome.ServiceBean> {
    public HomeSearchAdapter(Context context, int mode) {
        super(context, mode);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new HomeSearchViewHodler(mInflater.inflate(R.layout.recycler_item_layout,parent,false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, SearchHome.ServiceBean item, int position) {
        HomeSearchViewHodler homeViewHolder = (HomeSearchViewHodler) holder;
        ImageLoader.loadImage(Glide.with(mContext),homeViewHolder.iv_photo, NetManager.getFullUrl(item.getPhoto()),
                R.drawable.sy_touxiang,R.drawable.sy_touxiang);
        if(TextUtils.isEmpty(item.getImgs())){
            homeViewHolder.ll_images.setVisibility(View.GONE);
        }else {
            String[] images = item.getImgs().split(",");
            homeViewHolder.mTweetPicturesLayout.setImage(images);
        }
        homeViewHolder.tv_nick.setText(item.getSecondname());
        homeViewHolder.tv_type.setText(item.getServicecategoryname());
        homeViewHolder.tv_status.setText(item.getState());
        homeViewHolder.tv_content.setText(item.getRemark());
        homeViewHolder.tv_money.setText("¥"+item.getMoney_total());
        homeViewHolder.tv_time.setText(item.getCreatedate());
        homeViewHolder.tv_distance.setText(item.getDistance()+"km");
    }
    class HomeSearchViewHodler extends RecyclerView.ViewHolder{
        @BindView(R.id.iv_photo)
        CircleImageView iv_photo;
        @BindView(R.id.tv_nick)
        TextView tv_nick;
        @BindView(R.id.tv_status)
        TextView tv_status;
        @BindView(R.id.tv_type)
        TextView tv_type;
        @BindView(R.id.tv_content)
        TextView tv_content;
        @BindView(R.id.tv_money)
        TextView tv_money;
        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_distance)
        TextView tv_distance;
        @BindView(R.id.ll_images)
        LinearLayout ll_images;
        @BindView(R.id.mTweetPicturesLayout)
        TweetPicturesLayout mTweetPicturesLayout;
        public HomeSearchViewHodler(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
